Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't touch nor send messages to the root logger. #1380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sagostinho-nvidia
Copy link

@sagostinho-nvidia sagostinho-nvidia commented Dec 19, 2024

Description

Currently transformer_engine is writing to the root logger upon import, which implicitly initializes the root logger preventing downstream applications from controlling it effectively.

For further motivation on why the root logger should not be used by a library see https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

Note It is strongly advised that you do not log to the root logger in your library. Instead, use a logger with a unique and easily identifiable name, such as the name for your library’s top-level package or module. Logging to the root logger will make it difficult or impossible for the application developer to configure the logging verbosity or handlers of your library as they wish.

This PR addresses this problem by ensuring all logging calls are done through dedicated transformer_engine loggers.

Fixes #1294

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Changes

Please list the changes introduced in this PR:

  • Removes all calls to logging.info during transfomer_engine's (python) import which implicitly initializes the root logger preventing downstream applications from controlling it effectively.
  • Prevent sending messages to the root logger in transformer_engine/pytorch/attention.py, for similar reasons as the previous point.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Prior to this change, despite the user setting the basicConfig after the import, it's ignore because transformer_engine already implicitly initialized it.

>>> import logging
>>> import transformer_engine
>>> _logger = logging.getLogger("my logger")
>>> logging.basicConfig(level=logging.INFO)
>>> _logger.info("Hello")
>>>

after the change

>>> import logging
>>> import transformer_engine
>>> _logger = logging.getLogger("my logger")
>>> logging.basicConfig(level=logging.INFO)
>>> _logger.info("Hello")
INFO:my logger:Hello
>>>

---------

Signed-off-by: Sérgio Agostinho <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PyTorch] transformer engine modifies root logger
1 participant